/*
 * ThreadSort.java
 */
import java.util.*;

public class ThreadSort implements Runnable {
	private int startIndex;
	private int localArraySize;
	private int[] array, localArray;
	private Thread t;

	public ThreadSort(int pid, int a[], int startIndex, int localArraySize) {
		t = new Thread(this);
		this.array = a;
		this.startIndex = startIndex;
		this.localArraySize = localArraySize;
		localArray = new int[localArraySize];
		t.start();
	}// end constructor
	
	public void run() {  
		try {
			// compute the partition and create local array
			int j = startIndex;
			for(int i=0; i<localArraySize; i++,j++)
				localArray[i] = array[j];
			sort();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}// end method run
		 
	public void sort() {
		Arrays.sort(localArray);
	}// end method sort
	
	public int[] getLocalArray() {
		return localArray;
	}// end method getLocalArray
	
	public Thread getThread() {
		return t;
	}// end method getThread
	
	public int getArraySize() {
		return localArraySize;
	}// end method getArraySize
	
	public String toString() {
		String result = "";
		for(int i=0; i<localArray.length; i++)
			result += localArray[i] + " ";
		return result;
	}// end override method toString
}// end class ThreadSort
